﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aker.DevTeam;
using DevExpress.XtraEditors;

namespace Aker
{
    public partial class ImageViewer : XPopupForm
    {

        public int ProductId = -1;

        public ImageViewer()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterParent;
        }

        public ImageViewer(int productId)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterParent;
            this.ProductId = productId;
        }

        private void ImageViewer_Load(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Maximized;

            bool isArticle = ProductId != -1;
            pnlHeader.Visible = isArticle;
            if (isArticle)
            {
                try
                {
                    this.Text = ProductId.ToString();
                    byte[] photo = (byte[])Data.DM.ExecuteScalar("GetPhotoBig", ProductId);
                    picture.EditValue = photo;
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(Language.Error + ":" + ex.ToString(), Language.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            this.Text = Language.CameraViewer.ImageViewer;
            btnOriginal.Text = Language.CameraViewer.ShowOriginal;
        }


        private void btnOriginal_Click(object sender, EventArgs e)
        {
            using (ImageViewer iv = new ImageViewer())
            {
                DataTable dt = Data.DM.ExecuteDataTable("GetPhotos", ProductId);
                DataRow drPhotos = dt.Rows[0];
                iv.picture.EditValue = (byte[])drPhotos["Original"];
                iv.ShowDialog();
            }
        }
    }
}
